#-------------------------------------------------------------------------------
# Name:        utility.py
# Purpose:     Utility functions for SlideSpeech converters
#
# Author:      jgraves
#
# Created:     23/10/2012
# Copyright:   (c) John Graves 2012
# Licence:     MIT License
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import os

# dependency tester
def findDependency(program):

    def is_exe(fpath):
        return os.path.isfile(fpath)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
        if is_exe("."+os.sep+program):
            return program

    return None

if __name__ == '__main__':
    import sys

    print("Dependencies for Platform: {0}".format(sys.platform))
    
    if sys.platform.startswith("linux"):
        from audio_converter_linux import *
        from pdf_converter_linux import *
    elif sys.platform.startswith("darwin"):
        from audio_converter_osx import *
        from pdf_converter_osx import *
    elif sys.platform.startswith("win"):
        from audio_converter_windows import *
        from pdf_converter_windows import *
    
    print("\nAudio:")
    for dependency in AudioConfig.dependencies:
        name = findDependency(dependency)
        if name is None:
            raise RuntimeError("Missing dependency: {0}".format(dependency))
        else:
            print(name)

    print("\nPDF:")
    for dependency in PDFConfig.dependencies:
        name = findDependency(dependency)
        if name is None:
            raise RuntimeError("Missing dependency: {0}".format(dependency))
        else:
            print(name)
